
import os
import project, interface

def createTables(db):
    q = """
CREATE TABLE InterfaceChanges (
	origfuncid 		int 	NOT NULL references functions(funcid),
	newfuncid		int	NOT NULL references functions(funcid),
	datetime		timestamp(2)	NOT NULL,
PRIMARY KEY (origfuncid)
)
"""
    dropq = "drop table InterfaceChanges cascade;"

    try:
        print "cleaning InterfaceChanges table..."
        db.query(dropq)
        print "...OK!"
    except _pg.ProgrammingError:
            print "could not drop tables"
    try:
        print "creating InterfaceChanges table..."
        db.query(q)
        print "...OK!"
    except _pg.ProgrammingError, e:
        print "could not create tables"
        raise project.ProjectError("Could not create tables, cause:" + str(e))



def start(project, log):
    db = proj.getDatabase()
    interface.fillInterfaceChanges(db, log)
    
